home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 September / CHIP 1996 szeptember (CD07).zip / CHIP_CD07.ISO / sac / pack / lha266.exe / SFX_.ASM < prev   
Assembly Source File  |  1994-12-19  |  25KB  |  1,376 lines

  1. ;***********************************************
  2. ;    sfx_.asm -- self-extract module
  3. ;***********************************************
  4.  
  5. page    0, 128
  6. include    amscls.inc
  7.  
  8. $_init GEN
  9.  
  10. _TEXT    segment byte public 'CODE'
  11. _TEXT    ends
  12.  
  13. DGROUP    group    _BSS
  14.         assume    cs:_TEXT, ds:DGROUP
  15.  
  16. CRC16            equ        0a001h
  17. BufSiz            equ        04000h
  18.  
  19. NC            =        (200h - 2)
  20. NP            =        14
  21. NP6            =        17
  22. NT            =        19
  23. NPT            =        19
  24.  
  25. CBIT        =        9
  26. PBIT        =        4
  27. PBIT6        =        5
  28. TBIT        =        5
  29.  
  30. LzHead    struc
  31.         HeadSiz db        ?
  32.         HeadChk db        ?
  33.         HeadID    db        3 dup (?)
  34.         Method    db        ?
  35.                 db        ?
  36.         PacSiz    dw        2 dup (?)
  37.         OrgSiz    dw        2 dup (?)
  38.         FTime    dw        ?
  39.         FDate    dw        ?
  40.         FAttr    dw        ?
  41.         FnLen    db        ?
  42.         Fname    db        80h dup (?)
  43. LzHead    ends
  44.  
  45. _BSS    segment para public 'BSS'
  46. beginofdata        label    byte
  47.         public    crctbl
  48.         public    cpyhdr, infile, outfile
  49.         public    inpptr, inpbuf
  50.         public    curcrc, orgcrc
  51.         public    myname
  52.         public    pathname, fnnext, swchar
  53.         public    blocksize_
  54.         public    outpos
  55.         public    np, pbit
  56.  
  57. inpbuf            db        BufSiz dup (?)
  58. crctbl            dw        100h dup (?)
  59. cpyhdr            LzHead    1 dup (<?>)
  60. inpptr            dw        1 dup (?)
  61. infile            dw        1 dup (?)
  62. outfile            dw        1 dup (?)
  63. orgcrc            dw        1 dup (?)
  64. curcrc            dw        1 dup (?)
  65. blocksize_        dw        1 dup (?)
  66. outpos            dw        1 dup (?)
  67.  
  68. len_cnt            dw        17 dup (?)
  69. start            dw        17 dup (?)
  70. weight            dw        17 dup (?)
  71.  
  72. np                dw        1 dup (?)
  73. pbit            dw        1 dup (?)
  74.  
  75. public    len_cnt
  76. public    start
  77. public    weight
  78.  
  79.  
  80. left_            dw        2 * NC - 1 dup (?)
  81. right_            dw        2 * NC - 1 dup (?)
  82.  
  83. c_table_        dw        4096 dup (?)
  84. pt_table_        dw        256 dup (?)
  85. c_len_            db        NC dup (?)
  86. pt_len_            db        NPT dup (?)
  87.  
  88. public    left_
  89. public    right_
  90. public    c_table_
  91. public    pt_table_
  92. public    c_len_
  93. public    pt_len_
  94.  
  95. bitbuf_            dw        1 dup (?)
  96. subbitbuf_        db        1 dup (?)
  97. bitcount_        db        1 dup (?)
  98.  
  99. myname            db        80h dup (?)
  100. pathname        db        80h dup (?)
  101. fnnext            dw        1 dup (?)
  102. fnptr            dw        1 dup (?)
  103. swchar            db        1 dup (?)
  104. endBBS            label    byte
  105. _BSS            ends
  106.  
  107.                 public    dic_
  108. _DIC    segment para public
  109. dic_            db        8000h dup (?)
  110. _DIC    ends
  111.  
  112. _DIC1    segment byte public
  113.                 db        8000h dup (?)
  114. _DIC1    ends
  115.  
  116. _TEXT    segment byte public 'CODE'
  117.         assume    cs:_TEXT
  118.  
  119.         org        0100h
  120.  
  121.         public    start, main
  122.         public    BSSseg
  123.         public    #cright, crlf, space
  124.         public    absent, #myself, broken, extend
  125.         public    #subver
  126.  
  127. top:
  128.         jmp        main
  129.  
  130. BSSseg    =        (#endofcode - top + 10fh) / 10h
  131. mes_yn    equ        space - 1
  132. space    db        ' ', 0
  133. #cright    db        "LHA's SFX 2.65"
  134. #subver    db        "L (c) Yoshi, 1994"
  135. crlf    db        13, 10, 0
  136. absent    db        'Rename to '
  137. #myself    db        'FILENAME.EXT', 0
  138. overwt    db        'Overwrite ', 0
  139. yesno    db        '[Y/N] ', 0
  140. broken    db        'Broken file ', 0
  141. write    db        'Write', 0
  142. header    db        'Header', 0
  143. crcmes    db        'CRC'
  144. error    db        ' Error', 0
  145. auto    db        1, '!'
  146. autoflg db        '.' shr 1
  147.         db        'BAT'
  148. extend    db        0ffh
  149. attrib    db        0
  150.  
  151. envseg    =        002ch
  152. cmdcnt    =        0080h
  153. cmdline =        0081h
  154.  
  155. ;-----------------------------------------------
  156. ;        âüâCâôâïü[â`âô
  157. ;-----------------------------------------------
  158. main:
  159.         cld
  160.         mov        sp, offset top
  161.         mov        ax, cs
  162.         add        ax, BSSseg
  163.         mov        es, ax
  164.  
  165.         assume    es:DGROUP
  166.  
  167.         call    @getopt
  168.  
  169.         public    #getopt
  170. #getopt:
  171.         mov        bx, offset #cright
  172.         call    mesout
  173.         push    es
  174.         pop        ds
  175.  
  176.         assume    ds:DGROUP
  177. ;-----------------------------------------------
  178. ;        Get my name
  179. ;-----------------------------------------------
  180.         mov        ah, 30h
  181.         int        21h                                ; get DOS ver.
  182.         mov        bx, ax
  183.         push    ds
  184.         $_if <cmp al, 3>, AE                    ; if DOS ver. >= 3.00
  185.             mov        es, ss:[envseg]
  186.             xor        ax, ax
  187.             mov        di, ax
  188.             mov        cx, -1
  189.             $_do
  190.                 repne    scasb
  191.                 scasb
  192.             $_until , E
  193.             inc        ax
  194.             scasw
  195.             push    es
  196.             pop        ds
  197.             mov        dx, di
  198.             $_if , E
  199.                 call    openme
  200.             $_endif
  201.         $_endif
  202. brknenv:
  203.         push    cs
  204.         pop        ds
  205.         mov        dx, offset #myself
  206.         call    openme
  207.         $_if <cmp bl, 2>, E                    ; if DOS ver. = 2
  208.             mov        ax, ss:[0002h]            ;  get pathname from trash
  209.             sub        ax, 38h                    ;  of command.com
  210.             mov        ds, ax
  211.             mov        dx, 0009h
  212.             call    openme
  213.         $_endif
  214.         mov        bx, offset absent
  215.         jmp        errout1
  216. openme:
  217.         mov        ax, 3d00h
  218.         int        21h                                ; Open Myself
  219.         $_if , C
  220.             ret
  221.         $_endif
  222.         pop        cx                                ; pop old ip
  223.  
  224.         pop        ds
  225.         mov        infile, ax
  226.  
  227.         mov        bx, ax
  228.         xor        cx, cx
  229.  
  230. ifndef COM
  231.     exehdr    =        20h
  232. else
  233.     exehdr    =        0h
  234. endif
  235.  
  236.         mov        dx, (#endofcode - top) + exehdr
  237.  
  238.         public    #seeksize
  239. #seeksize:
  240.  
  241.         mov        ax, 4200h
  242.         int        21h                                ; Move a File Pointer
  243.         $_if , C
  244. brokenerr:
  245.             mov        bx, offset broken        ; Broken file
  246.             jmp        errout
  247.         $_endif
  248.         push    ds
  249.         pop        es
  250. ;---------------------------------------
  251. ;        make CRC table
  252. ;---------------------------------------
  253.         mov        di, offset crctbl
  254.         xor        dx, dx
  255.         $_do
  256.             mov        ax, dx
  257.             mov        cx, 8
  258.             $_do
  259.                 $_if <shr ax, 1>, C
  260.                     xor        ax, CRC16
  261.                 $_endif
  262.             $_until <LOOP>
  263.             stosw
  264.         $_until <inc dl>, Z
  265. ;---------------------------------------
  266.  
  267.         public mainloop
  268. mainloop:
  269.         $_while <TRUE>
  270.  
  271.             call    crlfout
  272. ; Get Header ---------------------------
  273.             mov        si, offset DGROUP:cpyhdr.HeadSiz
  274.             mov        dx, si
  275.             mov        cx, 1
  276.             mov        [si], ch
  277.             mov        bx, infile
  278.             mov        ah, 3fh
  279.             int        21h                        ; Read header size
  280.             dec        cx                        ; cx = 0
  281.             add        cl, [si]
  282.             $_if , Z
  283.                 jmp        exit
  284.             $_endif
  285.             inc        dx
  286.             inc        si
  287.  
  288.             inc        cx
  289.             mov        ah, 3fh
  290.             int        21h                        ; Read header
  291.  
  292. ; Test Header Sum ----------------------
  293.             lodsb
  294.             push    si                    ; cpyhdr.HeadID
  295.             dec        cx
  296.             dec        si
  297.             $_do
  298.                 inc        si
  299.                 sub        al, [si]
  300.             $_until <LOOP>
  301.             jne        errhdr
  302.             pop        si
  303.  
  304. ; Test Header ID -----------------------
  305.             lodsw
  306.             $_if <cmp ax, 'l-'>, NE, OR
  307.                 lodsw
  308.                 xchg    al, ah
  309.                 sub        ax, 'h0'
  310.                 mov        bp, ax                ; bp = method
  311.             $_c                 , NZ, AND
  312.             $_c  <sub ax, 0004h>, B, OR
  313.             $_c  <sub ax, 0003h>, A, OR
  314.                 lodsb
  315.             $_c  <sub al, '-'>, NZ
  316. errhdr:
  317.                 mov        bx, offset header
  318.                 jmp        errout
  319.             $_endif
  320.  
  321. ; Get original CRC ---------------------
  322.             mov        bx, offset DGROUP:cpyhdr.Fname
  323.             mov        dx, bx
  324.             mov        cx, [bx - 1]
  325.             add        bl, cl                ; doesn't carry up
  326.  
  327.             xchg    ax, [bx]            ; ax = 0, [bx] = CRC
  328.             mov        orgcrc, ax
  329.  
  330. ; Test Special File ? ------------------
  331.             mov        fnptr, dx
  332.             cmp        cx, 2101h                ; 01h, '!'
  333.             $_if , E
  334.                 mov        ax, 1
  335.                 jmp        mn7
  336.             $_endif
  337.  
  338.             call    @extended
  339.  
  340.         public    #extended
  341. #extended:
  342.  
  343.  
  344. ; Display File name --------------------
  345.             mov        word ptr [bx], 0 * 256 + ' '
  346.             mov        bx, dx
  347.             call    disp                    ; output file name
  348.             mov        ax, 4300h                ; get file attr
  349.             dec        bx
  350.             mov        byte ptr [bx], al
  351.             dec        bx
  352.  
  353. ; Is a directory ? ---------------------
  354.             $_if <cmp byte ptr [bx], '/'>, E
  355.                 mov        byte ptr [bx], al
  356.                 jmp        mn10
  357.             $_endif
  358.  
  359.             jcxz    mn9                        ; !.BAT ?
  360.  
  361. ; Check Existence of File --------------
  362. ;            mov        ax, 4300h                ; get file attr
  363.             int        21h                        ;    (for MS-DOS 3.3)
  364.             jc        mn1
  365.  
  366. ; Overwrite ? --------------------------
  367.             mov        bx, offset overwt    ; prompt
  368.             call    mesout
  369.             call    getyn
  370.             je        mn1
  371.  
  372. ; Skip to next File --------------------
  373.             mov        dx, DGROUP:cpyhdr.PacSiz        ; skip file
  374.             mov        cx, DGROUP:cpyhdr.PacSiz + 2
  375.  
  376.             mov        bx, infile
  377.             mov        ax, 4201h
  378.             int        21h                    ; Move a File Pointer
  379.             jmp        mn6
  380. mn9:
  381.             mov        cs:autoflg, 0dh
  382.  
  383. ; Create a New File --------------------
  384. mn1:
  385.             mov        cx, 0020h
  386.             mov        ah, 3ch
  387.             int        21h                    ; Create a File
  388.             $_if , C
  389.                 jmp        errcreat
  390.             $_endif
  391.  
  392. ; Decode -------------------------------
  393. mn7:
  394.             mov        outfile, ax
  395.  
  396.             xor        ax, ax
  397.             mov        curcrc, ax
  398.             dec        ax
  399.             mov        inpptr, ax
  400.  
  401.             push    dx
  402.             push    es
  403.             mov        ax, ds
  404.             add        ax, (endofdata - beginofdata + 0fh) / 10h
  405.             mov        es, ax
  406.             $_if <or bp, bp>, NZ
  407.                 call    decode
  408.             $_else
  409.                 call    copyall
  410.             $_endif
  411.             pop        es
  412.             pop        dx
  413.  
  414. ; Set Time-Stamp -----------------------
  415.             mov        bx, outfile
  416.             cmp        bx, 1                    ; file '!' ?
  417.             je        mn8
  418.  
  419.             push    dx
  420.             mov        dx, DGROUP:cpyhdr.FDate
  421.             mov        cx, DGROUP:cpyhdr.FTime
  422.             mov        ax, 5701h                ; set date
  423.             int        21h
  424.             call    close
  425.  
  426. ; Check CRC ----------------------------
  427.             mov        ax, curcrc
  428.             cmp        ax, orgcrc
  429.             pop        dx
  430.             jne        errcrc
  431.  
  432. mn10:
  433.             call    @setattr
  434.  
  435. public    #setattr
  436. #setattr:
  437.  
  438.  
  439.             jmp        mn6
  440. mn8:
  441.             call    getyn
  442.             jne        exit1
  443. mn6:
  444.         $_enddo
  445.         mov        bx, infile
  446.         call    close
  447.  
  448.         public    exit
  449. exit:
  450.         call    @autoexec
  451.  
  452.         public    #autoexec
  453. #autoexec:
  454. exit1:
  455.         xor        al, al
  456. exit2:
  457.         mov        ah, 4ch
  458.         int        21h
  459.  
  460. ;-----------------------------------------------
  461. ;        âGâëü[Åêù¥
  462. ;-----------------------------------------------
  463.         public    errhdr, errwrite, errout
  464. errcrc:
  465.         call    unlink
  466.         mov        bx, offset crcmes
  467.         jmp        short errout1
  468.  
  469. errwrite:
  470.         mov        bx, outfile
  471.         call    close
  472.         call    unlink
  473. errcreat:
  474.         mov        bx, offset write
  475.  
  476. errout:
  477.         call    mesout
  478.         mov        bx, offset error
  479. errout1:
  480.         call    mesout
  481.         mov        al, 1
  482.         jmp        exit2
  483.  
  484. ;-----------------------------------------------
  485. ;        get 'Y' or 'N'
  486. ;-----------------------------------------------
  487.         public    getyn
  488. getyn    proc    near
  489.         mov        bx, offset yesno                ; prompt
  490.         call    mesout
  491.         $_do
  492.             mov        ah, 08h
  493.             int        21h
  494.             and        al, 0dfh
  495.         $_until <cmp al, 'Y'>, E, OR
  496.         $_c        <cmp al, 'N'>, E
  497.         mov        bx, offset mes_yn
  498.         mov        cs:[bx], al
  499.         call    mesout
  500.         cmp        al, 'Y'
  501.         ret
  502. getyn    endp
  503.  
  504. ;-----------------------------------------------
  505. ;        é╗é╠é▄é▄Åoù═
  506. ;-----------------------------------------------
  507.         public    copyall
  508. copyall proc    near
  509.     $_while <TRUE>
  510.         mov        bx, offset DGROUP:cpyhdr.OrgSiz
  511.         mov        cx, 0FF00h
  512.         xor        dx, dx
  513.         sub        [bx], cx
  514.         sbb        word ptr 2[bx], dx
  515.         $_if ,C
  516.             add        cx, [bx]            ; ÄcéΦâoâCâgÉöé≡îvÄZ
  517.             jz        cpyend
  518.             mov        [bx], dx            ; Äƒé┼ÅIéφéΦ
  519.             mov        [bx + 2], dx
  520.         $_endif
  521.  
  522.         mov        bx, infile
  523.         mov        ah, 3fh
  524.         push    ds
  525.         push    es
  526.         pop        ds
  527.         int        21h
  528.         pop        ds
  529.         call    putbuf2
  530.     $_enddo
  531. cpyend:
  532.     ret
  533. copyall endp
  534.  
  535. ;-----------------------------------------------
  536. ;        CR, LF é╠Åoù═
  537. ;-----------------------------------------------
  538. crlfout    proc    near
  539.         mov        bx, offset crlf
  540. crlfout    endp
  541. ;-----------------------------------------------
  542. ;        âüâbâZü[âWé╠Åoù═
  543. ;-----------------------------------------------
  544.         public    mesout
  545. mesout    proc    near
  546.         push    ds
  547.         push    cs
  548.         pop        ds
  549.         call    disp
  550.         pop        ds
  551.         ret
  552. mesout    endp
  553.  
  554. ;-----------------------------------------------
  555. ;        display ASCIZ char
  556. ;-----------------------------------------------
  557.         public    disp
  558. disp    proc    near
  559.         push    ax
  560.         push    dx
  561.         $_do
  562.             mov        dl, [bx]
  563.             inc        bx
  564.             mov        ah, 02h
  565.             int        21h
  566.         $_until <cmp byte ptr [bx], 0>, E
  567.         pop        dx
  568.         pop        ax
  569.         ret
  570. disp    endp
  571.  
  572. ;-----------------------------------------------
  573. ;        getc
  574. ;            ax: 1 byte (return)
  575. ;-----------------------------------------------
  576.         public    getc
  577. getc    proc    near
  578.         mov        bx, inpptr
  579.         $_if <cmp bx, offset inpbuf + BufSiz>, AE
  580.     ;-----------------------------------------------
  581.     ;        buffer ôⁿù═
  582.     ;-----------------------------------------------
  583.             public    getbuf
  584.     getbuf    proc    near
  585.             push    cx
  586.             push    dx
  587.             mov        dx, offset DGROUP:inpbuf
  588.             mov        cx, BufSiz
  589.             mov        bx, offset DGROUP:cpyhdr.PacSiz
  590.             sub        [bx], cx
  591.             sbb        word ptr 2[bx], 0
  592.             $_if , C
  593.                 add        cx, [bx]
  594.             $_endif
  595.             mov        bx, infile
  596.             mov        ah, 3fh
  597.             int        21h                    ; Read from an Archive
  598.             mov        bx, dx
  599.             pop        dx
  600.             pop        cx
  601.     getbuf    endp
  602.     ;-----------------------------------------------
  603.         $_endif
  604.         mov        al, [bx]
  605.         inc        bx
  606.         mov        inpptr, bx
  607.         ret
  608. getc    endp
  609.  
  610. ;-----------------------------------------------
  611. ;        extract routines
  612. ;-----------------------------------------------
  613.         public    decode
  614. decode proc    near
  615.     mov        ax, NP                        ; NP = 14
  616.     mov        bx, PBIT                    ; PBIT = 4
  617.     $_if <cmp bp, 6>, AE
  618.         add     ax, 3                    ; mov    ax, NP6 = 17
  619.         inc     bx                        ; mov    bx, PBIT6 = 5
  620.     $_endif
  621.     mov        np, ax
  622.     mov        pbit, bx
  623.  
  624.     xor        ax, ax
  625.     mov        blocksize_, ax
  626.     mov        bitbuf_, ax
  627.     mov        subbitbuf_, al
  628.     mov        bitcount_, al
  629.  
  630.     mov        al,16
  631.     call    fillbuf_
  632.  
  633.     xor        di, di
  634.     xor        dx, dx
  635.  
  636.     xor        si, si
  637.     $_while <TRUE>
  638. ; Äƒë±Åoù═ɵô¬ê╩Æu
  639.         mov     outpos, si
  640. ; Äƒë±Åoù═é▄é┼é╠âoâCâgÉö
  641.         mov        cx, 8000h
  642.         add        dx, cx
  643.         mov        bx, offset cpyhdr.OrgSiz
  644.         xor        ax, ax
  645.         sub        [bx], cx
  646.         sbb        word ptr [bx + 2], ax
  647.         $_if ,C
  648.             add        dx, [bx]
  649.             mov        [bx], ax
  650.             mov        [bx + 2], ax
  651.             jz        putbuf
  652.         $_endif
  653.  
  654. $loop:
  655.         call    decode_c_st1_
  656.         $_if <or ah, ah>, Z
  657.             stosb
  658.             dec        dx
  659.             jnz        $loop
  660.         $_else
  661.             mov        cx, ax
  662.             sub        cx, 100h - 3
  663.             call    decode_p_st1_
  664.             mov        si, di
  665.             stc
  666.             sbb        si, ax
  667.             sub        dx, cx
  668.  
  669.             push    ds
  670.             push    es
  671.             pop        ds
  672.             rep        movsb
  673.             pop        ds
  674.  
  675.             ja        $loop
  676.         $_endif
  677. ;        int     1
  678.         push    dx
  679.         call    putbuf
  680.         pop        dx
  681.     $_enddo
  682.  
  683. ;$endloop:
  684. ;    ret
  685. decode endp
  686.  
  687. ;-----------------------------------------------
  688. ;        âoâbâtâ@é╠Åoù═
  689. ;-----------------------------------------------
  690.         public    putbuf
  691.         public    putbuf2
  692. putbuf    proc    near
  693.     mov        dx, outpos
  694.     mov        cx, di
  695.     sub        cx, dx
  696. ;    $_if <cmp cx, 8000h>, AE
  697.     $_if , S
  698.         mov        cx, 8000h
  699.     $_endif
  700. putbuf2:
  701.     jcxz    return
  702.     mov        bx, outfile
  703.     push    ds
  704.     push    es
  705.     pop        ds
  706.     mov        ah, 40h
  707.     int        21h
  708.     pop        ds
  709.     $_if <sub ax, cx>, NE
  710.         cmp        bx, 1
  711.         jne        errwrite
  712.     $_endif
  713. calccrc:
  714.     mov        si, dx
  715.     mov        bx, curcrc
  716. ;    xor        ah, ah                        ; ah = 0
  717. ;    cld
  718.     $_do
  719.         lods    byte ptr es:[si]
  720.         xor        bl, al
  721.         mov        al, bh
  722.         mov        bh, ah
  723.         shl        bx, 1
  724.         mov        bx, crctbl[bx]
  725.         xor        bx, ax
  726.     $_until <LOOP>
  727.     mov        curcrc, bx
  728.  
  729.     cmp        outfile, 1
  730.     je        return
  731.     mov        ah, 02h
  732.     mov        dl, '.'
  733.     jmp        short int21_ret
  734. ;    int    21h
  735. ;    ret
  736. putbuf    endp
  737.  
  738. ;-----------------------------------------------
  739. ;        âtâ@âCâïé╠ close
  740. ;-----------------------------------------------
  741.         public    close
  742. close    proc    near
  743.         mov        ah, 3eh
  744.         jmp        short int21_ret                    ; int    21h
  745.                                                 ; ret
  746. close    endp
  747.  
  748. ;-----------------------------------------------
  749. ;        âtâ@âCâïé╠ìφÅ£
  750. ;-----------------------------------------------
  751.         public    unlink
  752. unlink    proc    near
  753.         mov        dx, fnptr
  754.         mov        ah, 41h                            ; unlink
  755. int21_ret:
  756.         int        21h
  757. return:
  758.         ret
  759. unlink    endp
  760.  
  761.  
  762. ;-----------------------------------------------
  763. ;        extract routines
  764. ;-----------------------------------------------
  765. ;    static void read_pt_len(short nn, short nbit, short i_special)
  766. ;public    read_pt_len_
  767. read_pt_len_    proc    near
  768.     push    si
  769.     mov        al, dl
  770.     call    getbits_
  771.     $_if <cmp ax, si>, A
  772.         jmp        brokenerr
  773.     $_endif
  774.     mov        di, offset DGROUP:pt_len_
  775.     $_if <or ax, ax>, Z
  776.         pop        cx
  777.         rep        stosb
  778.         mov        al, dl
  779.         call    getbits_
  780.         mov        cx, 256
  781.         mov        di, offset DGROUP:pt_table_
  782.         rep        stosw
  783.         ret
  784.     $_else
  785.         mov        dx, cx            ; dl = i_special
  786.         add        dx, di
  787.         mov        si, di
  788.         add        si, ax            ; ax = n
  789.         $_do
  790.             mov        al, 3
  791.             call    getbits_
  792.             $_if <cmp al, 7>, E
  793.                 mov        bx, bitbuf_
  794.                 $_while <shl bx, 1>, C
  795.                     inc        ax
  796.                 $_enddo
  797.                 push    ax
  798.                 sub        al, 6
  799.                 call    fillbuf_
  800.                 pop        ax
  801.             $_endif
  802.             stosb
  803.             $_if <cmp di, dx>, E
  804.                 mov        al, 2
  805.                 call    getbits_
  806.                 mov        cx, ax
  807.                 xor        al, al
  808.                 rep        stosb
  809.             $_endif
  810.         $_until <cmp di, si>, AE
  811.         pop        si                        ; nn
  812.         mov        bp, offset DGROUP:pt_len_
  813.         lea        cx, [bp + si]    ;    lea        cx, DGROUP:pt_len_[si]
  814.         sub        cx, di
  815.         xor        al, al
  816.         rep        stosb
  817.         mov        ax, si
  818.         mov        cx, 8
  819.         mov        di, offset DGROUP:pt_table_
  820.         jmp        make_table_
  821.     $_endif
  822. read_pt_len_    endp
  823.  
  824. ;    static void read_c_len(void)
  825. ;public    read_c_len_
  826. read_c_len_    proc    near
  827.     mov        al, CBIT
  828.     call    getbits_
  829.     $_if <cmp ax, NC>, A
  830.         jmp        brokenerr
  831.     $_endif
  832.     mov        di, offset DGROUP:c_len_
  833.     $_if <or ax, ax>, Z
  834.         mov        cx, NC
  835.         rep        stosb
  836.         mov        al, CBIT
  837.         call    getbits_
  838.         mov        cx, 4096
  839.         mov        di, offset DGROUP:c_table_
  840.         rep        stosw
  841.         ret
  842.     $_else
  843.         mov        dx, di
  844.         add        dx, ax            ; ax = n
  845.         push    di
  846.         $_do
  847.             mov        ax, bitbuf_
  848.             mov        bl, ah
  849.             xor        bh, bh
  850.             shl        bx, 1
  851.             mov        bx, pt_table_[bx]
  852.  
  853.             mov        si, offset read_c_len_1
  854.             mov        cx, NT
  855.             jmp        tree1
  856.  
  857. if 0
  858.             $_while <cmp bx, NT>, AE
  859.                 $_if <shl al, 1>, C
  860.                     mov        bx, right_[bx]
  861.                 $_else
  862.                     mov        bx, left_[bx]
  863.                 $_endif
  864.             $_enddo
  865. endif
  866.  
  867. read_c_len_1:
  868.             push    bx
  869.             mov        al, pt_len_[bx]
  870.             call    fillbuf_
  871.             pop        ax
  872.             $_if <sub ax, 2>, BE
  873.                 $_if , Z
  874.                     mov        al, CBIT
  875.                     call    getbits_
  876.                     add        ax, 20
  877.                     mov        cx, ax
  878.                 $_else
  879.                     $_if <inc ax>, Z
  880.                         mov        al, 4
  881.                         call    getbits_
  882.                         add        ax, 3
  883.                         mov        cx, ax
  884.                     $_else
  885.                         mov        cx, 1
  886.                     $_endif
  887.                 $_endif
  888.                 xor        al, al
  889.                 rep        stosb
  890.             $_else
  891.                 stosb
  892.             $_endif
  893.         $_until <cmp di, dx>, AE
  894.         mov        cx, offset DGROUP:c_len_ + NC
  895.         sub        cx, di
  896.         xor        al, al
  897.         rep        stosb
  898.         mov        ax, NC
  899.         pop        bp
  900.         mov        cx, 12
  901.         mov        di, offset DGROUP:c_table_
  902.         jmp        make_table_
  903.     $_endif
  904. read_c_len_    endp
  905.  
  906. ;    ushort decode_c_st1(void)
  907. decode_c    proc    near
  908. ;    not entry here
  909. decode_c_st1_2:
  910.     push    es
  911.     push    ds
  912.     pop        es
  913.     push    di
  914.     push    dx
  915.     mov        al, 16
  916.     call    getbits_
  917.     dec        ax
  918.     mov        blocksize_, ax
  919.     mov        si, NT
  920.     mov        dl, TBIT
  921.     mov        cx, 3
  922.     call    read_pt_len_
  923.     call    read_c_len_
  924.     mov        si, np
  925.     mov        dx, pbit
  926.     mov        cx, -1
  927.     call    read_pt_len_
  928.     pop        dx
  929.     pop        di
  930.     pop        es
  931.     jmp        decode_c_st1_3
  932. ;
  933. ;    entry here
  934. ;
  935. public    decode_c_st1_
  936. decode_c_st1_:
  937.     sub        blocksize_, 1
  938.     jc        decode_c_st1_2
  939. decode_c_st1_3:
  940.     mov        bx, bitbuf_
  941.     mov        cl, 4
  942.     shr        bx, cl
  943.     shl        bx, 1
  944.     mov        bx, c_table_[bx]
  945.     $_if    <cmp bx, NC>, B
  946. decode_c_st1_1:
  947.         push    bx
  948.         mov        al, c_len_[bx]
  949.         call    fillbuf_
  950.         pop        ax
  951.         ret
  952.     $_endif
  953.     mov        ax, bitbuf_
  954.     shl        al, cl
  955.     mov        si, offset decode_c_st1_1
  956.     mov        cx, NC
  957. tree0:
  958.     $_do
  959.         $_if <shl al, 1>, C
  960.             mov        bx, right_[bx]
  961.         $_else
  962.             mov        bx, left_[bx]
  963.         $_endif
  964. tree1:
  965.     $_until <cmp bx, cx>, B
  966.     jmp        si
  967. decode_c    endp
  968.  
  969. ;    ushort decode_p_st1(void)
  970. public    decode_p_st1_
  971. decode_p_st1_    proc    near
  972. ;---------------------------------------------------------------
  973. ;    ushort decode_p_st1(void)
  974. ;---------------------------------------------------------------
  975.     push    cx
  976.     xor        bh, bh
  977.     mov        bl, byte ptr bitbuf_ + 1
  978.     shl        bx, 1
  979.     mov        bx, pt_table_[bx]
  980.     $_if    <cmp bx, np>, B
  981. decode_p_st1_1:
  982.         push    bx
  983.         mov        al, pt_len_[bx]
  984.         call    fillbuf_
  985.         pop        ax
  986.         $_if <cmp al, 1>, A
  987.             dec        ax
  988.             mov        cx, ax
  989.             call    getbits_
  990.             mov        bx, 1
  991.             shl        bx, cl
  992.             or        ax, bx
  993.         $_endif
  994.         pop        cx
  995.         ret
  996.     $_endif
  997.     mov        al, byte ptr bitbuf_
  998.     mov        si, offset decode_p_st1_1
  999.     mov        cx, np
  1000.     jmp        tree0
  1001.  
  1002. if 0
  1003.     $_do
  1004.         $_if <shl al, 1>, C
  1005.             mov        bx, right_[bx]
  1006.         $_else
  1007.             mov        bx, left_[bx]
  1008.         $_endif
  1009.     $_until <cmp bx, np>, B
  1010.     jmp        decode_p_st1_1
  1011. endif
  1012. decode_p_st1_    endp
  1013.  
  1014.  
  1015. ;---------------------------------------------------------------
  1016. ;    void make_table(short nchar, uchar bitlen[],
  1017. ;                             ax            bp
  1018. ;                    short tablebits, ushort table[])
  1019. ;                                 cx            di
  1020. ;---------------------------------------------------------------
  1021. _BSS    segment word public 'BSS'
  1022. avail_mt        dw        1 dup (?)
  1023. nchar            dw        1 dup (?)
  1024. bitlen            dw        1 dup (?)
  1025. tablebits        dw        1 dup (?)
  1026. table            dw        1 dup (?)
  1027. restbits        db        1 dup (?)
  1028.  
  1029. public    avail_mt
  1030. public    nchar
  1031. public    bitlen
  1032. public    tablebits
  1033. public    table
  1034. public    restbits
  1035. _BSS    ends
  1036.  
  1037.     public    make_table_
  1038. make_table_    proc    near
  1039.     mov        nchar, ax
  1040.     shl        ax, 1
  1041.     mov        avail_mt, ax
  1042.     mov        tablebits, cx
  1043.     mov        table, di
  1044.     mov        al, 16
  1045.     sub        al, cl
  1046.     mov        restbits, al
  1047.  
  1048.     mov        ax, 1
  1049.     shl        ax, cl
  1050.     mov        cx, ax
  1051.     xor        ax, ax
  1052.     rep        stosw
  1053.  
  1054.     xor        si, si
  1055.     mov        bx, 8000h
  1056.     mov        dx, 1
  1057.     $_do
  1058.         mov        di, bp
  1059.         mov        cx, nchar
  1060.         $_do
  1061.             mov        al, dl
  1062.             repne    scasb
  1063.             jne        mt1
  1064.             mov        ax, di
  1065.             sub        ax, bp
  1066.             dec        ax
  1067.             push    cx
  1068.             push    di
  1069. ;            ; bx = weight
  1070. ;            ; si = code
  1071. ;            ; dx = len
  1072.             mov        cl, restbits
  1073.             mov        di, si
  1074.             shr        di, cl
  1075.             shl        di, 1
  1076.             add        di, table
  1077.             push    bx
  1078.             $_if <cmp dx, tablebits>, BE
  1079.                 shr        bx, cl
  1080.                 mov        cx, bx
  1081.                 rep        stosw
  1082.             $_else
  1083. ;        /* ìéé│ n é╠ tree é≡ì∞éΘ */
  1084. ;                ; di = taddr
  1085. ;                ; si = 
  1086. ;                ; cx = 
  1087. ;                ; ax = char
  1088.                 push    si
  1089.                 mov        cx, tablebits
  1090.                 shl        si, cl
  1091.                 neg        cx
  1092.                 add        cx, dx
  1093.                 $_do
  1094.                     $_if <cmp word ptr [di], 0>, E
  1095. ;                /* Ä}é¬é▄é╛ëäé╤é─éóé╚é»éΩé╬ì∞éΘ */
  1096.                         mov        bx, avail_mt
  1097.                         mov        right_[bx], 0
  1098.                         mov        left_[bx], 0
  1099.                         mov        [di], bx
  1100.                         add        avail_mt, 2
  1101.                     $_endif
  1102.                     mov        di, [di]
  1103.                     $_if <shl si, 1>, C
  1104.                         add        di, offset DGROUP:right_
  1105.                     $_else
  1106.                         add        di, offset DGROUP:left_
  1107.                     $_endif
  1108.                 $_until <LOOP>
  1109.                 mov        [di], ax
  1110.                 pop        si
  1111.             $_endif
  1112.             pop        bx
  1113.             pop        di
  1114.             pop        cx
  1115.             add        si, bx
  1116.             jc        mt2
  1117.         $_until <or cx, cx>, Z
  1118. mt1:
  1119.         inc        dx
  1120.         shr        bx, 1
  1121.     $_until , C
  1122. public mt2
  1123. mt2:
  1124.     ret
  1125. make_table_    endp
  1126.  
  1127. ;-----------------------------------------------
  1128. ;        ôⁿù═é⌐éτéÄârâbâgé≡ô╛éΘ
  1129. ;-----------------------------------------------
  1130. ;
  1131. ;ushort getbits(uchar n)
  1132. ;{
  1133.     public    getbits_
  1134. getbits_:        
  1135.     push    cx
  1136.     mov        cl, 16
  1137.     sub        cl, al
  1138.     push    bitbuf_
  1139.     call    fillbuf_
  1140.     pop        ax
  1141.     shr        ax, cl
  1142.     pop        cx
  1143.     ret
  1144.  
  1145. ;
  1146. ;void fillbuf(uchar n)  /* Shift bitbuf n bits left, read n bits */
  1147. ;{
  1148.  
  1149.     public    fillbuf_
  1150. fillbuf_:
  1151.     push    cx
  1152.     push    dx
  1153.     mov        ch, al
  1154.     mov        cl, bitcount_
  1155.     mov        dx, bitbuf_
  1156.     mov        al, subbitbuf_
  1157.     $_if <cmp ch, cl>, A
  1158.         sub        ch, cl
  1159.         shl        dx, cl
  1160.         rol        al, cl
  1161.         add        dl, al
  1162.         mov        cl, 8
  1163. fb1:
  1164.         call    getc
  1165.         $_if <cmp ch, cl>, A
  1166.             sub        ch, cl
  1167.             mov        dh, dl
  1168.             mov        dl, al
  1169.             jmp        fb1
  1170.         $_endif
  1171.     $_endif
  1172.     sub        cl, ch
  1173.     mov        bitcount_, cl
  1174.     mov        cl, ch
  1175.     xor        ah, ah
  1176.     shl        dx, cl
  1177.     shl        ax, cl
  1178.     add        dl, ah
  1179.     mov        bitbuf_, dx
  1180.     mov        subbitbuf_, al
  1181.     pop        dx
  1182.     pop        cx
  1183.     ret
  1184.  
  1185.         public    #endofshort
  1186. #endofshort:
  1187.  
  1188.         public    @autoexec
  1189. @autoexec:
  1190.         $_if <cmp cs:autoflg, 0dh>, E
  1191.             push    cs
  1192.             pop        es
  1193.             mov        bx, (offset resident - top + 100h + 15) / 16
  1194.             mov        ah, 4ah
  1195.             int        21h
  1196.             push    cs
  1197.             pop        ds
  1198.             mov        si, offset auto
  1199.             int        2eh                        ; execute
  1200.         $_endif
  1201.         jmp        #autoexec
  1202.  
  1203. resident:
  1204.  
  1205. ;-----------------------------------------------
  1206. ;        Get options
  1207. ;-----------------------------------------------
  1208.         public    @getopt
  1209. @getopt:
  1210.         mov        ax, 3700h
  1211.         int        21h                                ; get switch char
  1212.         mov        si, cmdline
  1213.         mov        es:swchar, dl
  1214.  
  1215.         mov        es:fnnext, offset DGROUP:pathname
  1216.         $_do
  1217.             lodsb
  1218.             $_if <cmp al, ' '>, A
  1219.                 $_if <cmp al, es:swchar>, E, OR
  1220.                 $_c     <cmp al, '-'>, E
  1221. lp0:
  1222.                     lodsb
  1223.                     cmp        al, ' '
  1224.                     jbe        lp1
  1225.                     or        al, 20h
  1226.                     $_switch
  1227.                     $_case <cmp al, '!'>, E
  1228.                         shl        cs:autoflg, 1
  1229.                     $_case <cmp al, 'x'>, E
  1230.                         inc        cs:extend
  1231.                     $_case <cmp al, 'a'>, E
  1232.                         inc        cs:attrib
  1233.                     $_default
  1234.                         cmp        al, 'e'
  1235.                         jne        lp0
  1236.                         lodsb
  1237.                     $_endswitch
  1238.                 $_endif
  1239.                 dec        si
  1240.                 mov        di, offset DGROUP:pathname
  1241.                 push    si
  1242.                 call    convert
  1243.                 pop        si
  1244.                 push    ax
  1245.                 mov        al, '/'
  1246.                 call    trans
  1247.                 mov        al, '/'
  1248.                 $_if <cmp ah, al>, NE, AND
  1249.                 $_c  <cmp ah, ':'>, NE
  1250.                     stosb
  1251.                 $_endif
  1252.                 mov        es:fnnext, di
  1253.                 pop        ax
  1254. lp1:
  1255.             $_endif
  1256.         $_until <cmp al, 0dh>, E
  1257.         ret
  1258.  
  1259.         public    @extended
  1260. @extended:
  1261.             mov        si, dx
  1262.             mov        di, offset auto + 1        ; !.BAT ?
  1263.             cmp        cl, 5
  1264.             jne        mn5
  1265.             push    es
  1266.             push    cs
  1267.             pop        es
  1268.             xor        ch, ch
  1269.             rep        cmpsb
  1270.             pop        es
  1271.             je        mn2
  1272.  
  1273. ; -x switch ----------------------------
  1274. mn5:
  1275.             mov        si, dx
  1276.             mov        cx, si
  1277.             call    convert
  1278.             $_if <cmp cs:extend, 0>, E
  1279.                 mov        dx, cx            ; last delim
  1280.             $_endif
  1281.  
  1282. ; -eDIRECTORY --------------------------
  1283.             mov        si, dx
  1284.             mov        al, [si]
  1285.             $_if <cmp al, '/'>, NE
  1286.                 mov        di, fnnext
  1287.                 call    trans
  1288.                 mov        bx, di
  1289.                 mov        dx, offset DGROUP:pathname
  1290.             $_else
  1291.                 mov        ax, word ptr DGROUP:pathname
  1292.                 $_if <cmp ah, ':'>, E
  1293.                     dec        dx
  1294.                     dec        dx
  1295.                     mov        di, dx
  1296.                     mov        [di], ax    ; brakes FnLen and
  1297.                 $_endif                    ;    upper byte of FAttr
  1298.             $_endif
  1299.  
  1300. ; Make Directories ---------------------
  1301.             mov        si, dx
  1302.             $_do
  1303.                 lodsb
  1304.                 $_if <cmp al, '/'>, E
  1305.                     mov        byte ptr [si - 1], 0
  1306.                     mov        ah, 39h ; make dir
  1307.                     int        21h
  1308.                     mov        byte ptr [si - 1], '/'
  1309.                 $_endif
  1310.             $_until <cmp si, bx>, AE
  1311.  
  1312.             mov        fnptr, dx
  1313.             mov        cx, 1
  1314. mn2:
  1315.             ret
  1316.  
  1317. ; Set File Attributes ------------------
  1318.         public    @setattr
  1319. @setattr:
  1320.         $_if <cmp attrib, 0>, NE
  1321.             mov        cl, byte ptr DGROUP:cpyhdr.FAttr
  1322.             and        cx, 2fh
  1323.             mov        ax, 4301h
  1324.             int        21h                ; Set File Attributes
  1325.         $_endif
  1326.         ret
  1327.  
  1328. ;-----------------------------------------------
  1329. ;        convert '\' to '/' & terminater
  1330. ;-----------------------------------------------
  1331. conv    proc    near
  1332.         $_do
  1333.             $_if <cmp al, '\'>, E, OR
  1334.             $_c  <cmp al, '/'>, E
  1335.                 mov        byte ptr -1[si], '/'
  1336.                 mov        cx, si
  1337.             $_endif
  1338. ; is kanji ---------------------
  1339.             and        al, 0e0h
  1340.             shl        al, 1
  1341.             $_if , C, AND
  1342.             $_c  , PE
  1343.                 inc        si
  1344.             $_endif
  1345. ; ------------------------------
  1346. convert:
  1347.             lodsb
  1348.         $_until <cmp al, ' '>, BE
  1349.         dec        si
  1350.         mov        byte ptr [si], 0
  1351.         ret
  1352. conv    endp
  1353.  
  1354. ;-----------------------------------------------
  1355. ;        transfer string
  1356. ;-----------------------------------------------
  1357. trans    proc    near
  1358.         $_do
  1359.             mov        ah, al
  1360.             lodsb
  1361.             stosb
  1362.         $_until <or al, al>, E
  1363.         dec        di
  1364.         ret
  1365. trans    endp
  1366.  
  1367.         public    #endofcode
  1368. #endofcode:
  1369. _TEXT    ends
  1370.  
  1371.         public    endofdata
  1372. _BSS    segment para public 'BSS'
  1373. endofdata        label    byte
  1374. _BSS    ends
  1375.         end        top
  1376.